cytoscape-cola
Description
The Cola.js physics simulation layout for Cytoscape.js (demo, non-animated demo, compound demo, constraint demo)
The cola
layout uses a force-directed physics simulation with several sophisticated constraints, written by Tim Dwyer. For more information about Cola and its parameters, refer to its documentation.
It supports noncompound and compound graphs well.
Dependencies
- Cytoscape.js ^3.2.0
- Cola.js ^3.1.2
Usage instructions
Download the library:
- via npm:
npm install cytoscape-cola
, - via bower:
bower install cytoscape-cola
, or - via direct download in the repository (probably from a tag).
Import the library as appropriate for your project:
ES import:
import cytoscape from 'cytoscape';
import cola from 'cytoscape-cola';
cytoscape.use( cola );
CommonJS require:
let cytoscape = require('cytoscape');
let cola = require('cytoscape-cola');
cytoscape.use( cola );
AMD:
require(['cytoscape', 'cytoscape-cola'], function( cytoscape, cola ){
cola( cytoscape );
});
Plain HTML/JS has the extension registered for you automatically, because no require()
is needed.
API
Call the layout, e.g. cy.layout({ name: 'cola', ... })
, with options:
var defaults = {
animate: true,
refresh: 1,
maxSimulationTime: 4000,
ungrabifyWhileSimulating: false,
fit: true,
padding: 30,
boundingBox: undefined,
nodeDimensionsIncludeLabels: false,
ready: function(){},
stop: function(){},
randomize: false,
avoidOverlap: true,
handleDisconnected: true,
convergenceThreshold: 0.01,
nodeSpacing: function( node ){ return 10; },
flow: undefined,
alignment: undefined,
gapInequalities: undefined,
centerGraph: true,
edgeLength: undefined,
edgeSymDiffLength: undefined,
edgeJaccardLength: undefined,
unconstrIter: undefined,
userConstIter: undefined,
allConstIter: undefined,
};
Notes
- The
alignment
option isn't as flexible as the raw Cola option. Here, only integers can be used to specify relative positioning, so it's a bit limited. If you'd like to see a more sophisticated implementation, please send a pull request.
Build targets
npm run test
: Run Mocha tests in ./test
npm run build
: Build ./src/**
into cytoscape-cola.js
npm run watch
: Automatically build on changes with live reloading (N.b. you must already have an HTTP server running)npm run dev
: Automatically build on changes with live reloading with webpack dev servernpm run lint
: Run eslint on the source
N.b. all builds use babel, so modern ES features can be used in the src
.
Publishing instructions
This project is set up to automatically be published to npm and bower. To publish:
- Build the extension :
npm run build:release
- Commit the build :
git commit -am "Build for release"
- Bump the version number and tag:
npm version major|minor|patch
- Push to origin:
git push && git push --tags
- Publish to npm:
npm publish .
- If publishing to bower for the first time, you'll need to run
bower register cytoscape-cola https://github.com/cytoscape/cytoscape.js-cola.git
- Make a new release for Zenodo.